package com.meilai.project.controller.db;

import com.meilai.project.entity.system.Router;
import com.meilai.project.mapper.system.RouterMapper;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(value = "测试", description = "test")
@RestController
@RequestMapping("public/web/test")
public class TestController {

    @Autowired
    RouterMapper routerMapper;

    @GetMapping("/router/{id}")
    public List<Router> selectTree(@PathVariable long id){
        List<Router> list = new ArrayList<>();
        selectTree(id,list);
        return list;
    }

    private void selectTree(long id,List<Router> list){
        Router router = routerMapper.selectById(id);
        list.add(router);
        if(router.getPid()!=null){
            selectTree(router.getPid(),list);
        }
    }
}
